package com.ruoyi.st.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.response.JsonResult;
import com.ruoyi.st.domain.StAudience;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.st.domain.StAddrDetail;
import com.ruoyi.st.service.IStAddrDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import springfox.documentation.spring.web.json.Json;

/**
 * 地址详情Controller
 * 
 * @author ruoyi
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/st/addrDetail")
public class StAddrDetailController extends BaseController
{
    @Autowired
    private IStAddrDetailService stAddrDetailService;

    /**
     * 查询地址详情列表
     */
    @PreAuthorize("@ss.hasPermi('st:addrDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(StAddrDetail stAddrDetail)
    {
        startPage();
        List<StAddrDetail> list = stAddrDetailService.selectStAddrDetailList(stAddrDetail);
        return getDataTable(list);
    }

    /**
     * 通过userId查询对应的观演人列表
     * @Param userId
     * @return List<StAudience>
     */
    @GetMapping("/listByUserId/{userId}")
    public JsonResult selectListByUserId(@PathVariable("userId") Long userId) {
        if (userId == null) {
            throw new IllegalArgumentException("User ID is required");
        }
        List<StAddrDetail> stAddrDetailList = stAddrDetailService.selectStAddrDetailByUserId(userId);
        return JsonResult.ok(stAddrDetailList);
    }

    /**
     * 导出地址详情列表
     */
    @PreAuthorize("@ss.hasPermi('st:addrDetail:export')")
    @Log(title = "地址详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StAddrDetail stAddrDetail)
    {
        List<StAddrDetail> list = stAddrDetailService.selectStAddrDetailList(stAddrDetail);
        ExcelUtil<StAddrDetail> util = new ExcelUtil<StAddrDetail>(StAddrDetail.class);
        util.exportExcel(response, list, "地址详情数据");
    }

    /**
     * 获取地址详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('st:addrDetail:query')")
    @GetMapping(value = "/{id}")
    public JsonResult getInfo(@PathVariable("id") Long id)
    {
        StAddrDetail stAddrDetail = stAddrDetailService.selectStAddrDetailById(id);
        return JsonResult.ok(stAddrDetail);
    }

    /**
     * 新增地址详情
     */
//    @PreAuthorize("@ss.hasPermi('st:addrDetail:add')")
    @Log(title = "地址详情", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addAddr")
    public JsonResult add(@RequestBody StAddrDetail stAddrDetail)
    {

        return JsonResult.ok(stAddrDetailService.insertStAddrDetail(stAddrDetail));
    }

    /**
     * 修改地址详情
     */
//    @PreAuthorize("@ss.hasPermi('st:addrDetail:edit')")
    @Log(title = "地址详情", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update")
    public AjaxResult edit(@RequestBody StAddrDetail stAddrDetail)
    {
        return toAjax(stAddrDetailService.updateStAddrDetail(stAddrDetail));
    }

    /**
     * 删除地址详情
     */
//    @PreAuthorize("@ss.hasPermi('st:addrDetail:remove')")
    @Log(title = "地址详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stAddrDetailService.deleteStAddrDetailByIds(ids));
    }

    @DeleteMapping("/del/{id}")
    public JsonResult removeById(@PathVariable Long id)
    {
        return JsonResult.ok(stAddrDetailService.deleteStAddrDetailById(id));
    }
}
